<template>
  <el-dialog
    title="交易流水记录"
    :visible.sync="visible"
    width="720px"
    append-to-body
  >
    <avue-crud
      ref="crud"
      :data="tableData"
      :table-loading="tableLoading"
      :option="changeLogOption"
    ></avue-crud>
  </el-dialog>
</template>
<script>
import { changeLogOption } from '@/const/crud/pet/adoptionRecord';
import { adoptChangeLogRecord } from '@/api/core/adopt';
export default {
  props: {
    value: {
      type: Boolean,
      default: false,
    },
    id: {
      type: String,
    },
  },
  data() {
    return {
      changeLogOption,
      tableData: [],
      tableLoading: false,
    };
  },
  computed: {
    visible: {
      get() {
        return this.value;
      },
      set(val) {
        this.$emit('input', val);
      },
    },
  },
  watch: {
    visible(val) {
      if (val) {
        this.getList();
      } else {
        this.tableLoading = false;
        this.tableData = [];
      }
    },
  },
  methods: {
    getList() {
      this.tableLoading = true;
      adoptChangeLogRecord(this.id).then((res) => {
        this.tableLoading = false;
        if (res.data.code === 0) {
          res.data.data.forEach((element) => {
            console.log(JSON.parse(element.userNames));
            if (element.userNames) {
              element.userNames = JSON.parse(element.userNames).join(',');
            }
            if (element.oldNames) {
              element.oldNames = JSON.parse(element.oldNames).join(',');
            }
            this.tableData.push(element);
          });
          // this.tableData = res.data.data;
          // this.
          // console.log('tableData', this.tableData);
        }
      });
    },
  },
};
</script>
